<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>板块管理</title>
    <link rel="shortcut icon" href="/static/img/logo/favicon.ico" />
    <link href="/static/assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/css/blue.css" id="theme" rel="stylesheet">

</head>

<body class="fix-header card-no-border">
<div id="main-wrapper">
    <header class="topbar">
        <nav class="navbar top-navbar navbar-toggleable-sm navbar-light">
            <div class="text-light navbar-collapse">欢迎您，管理员
            </div>
        </nav>
    </header>
    <aside class="left-sidebar">
        <div class="scroll-sidebar">
            <nav class="sidebar-nav">
                <ul id="sidebarnav">
                    <li>
                        <a href="/admin-home" class="waves-effect"><i class="fa fa-clock-o m-r-10"
                                                                      aria-hidden="true"></i>帖子管理</a>
                    </li>
                    <li>
                        <a href="/announcement" class="waves-effect"><i class="fa fa-user m-r-10"
                                                                        aria-hidden="true"></i>公告管理</a>
                    </li>
                    <li class="">
                        <a href="/kind-manage" class="waves-effect"><i class="fa fa-table m-r-10"
                                                                       aria-hidden="true"></i>板块管理</a>
                    </li>
                    <li>
                        <a href="/file-manage" class="waves-effect"><i class="fa fa-table m-r-10"
                                                                       aria-hidden="true"></i>文件管理</a>
                    </li>
                    <li class="active">
                        <a href="/room-manage" class="waves-effect"><i class="fa fa-table m-r-10"
                                                                       aria-hidden="true"></i>房间管理</a>
                    </li>
                </ul>
            </nav>
        </div>
    </aside>
    <div class="page-wrapper">
        <div class="container-fluid">
            <div class="row page-titles">
                <div class="col-md-6 col-8 align-self-center">
                    <h3 class="text-themecolor m-b-0 m-t-0">房间管理</h3>
                </div>
            </div>
            <div class="row">
                <!-- column -->
                <div class="col-sm-12">
                    <div class="">
                        <div class="">
                            <div class="table-responsive">
                                <table class="table">
                                    <thead>
                                    <tr>
                                        <th style="width: 20%;">ID</th>
                                        <th>房间名称</th>
                                        <th style="width: 25%;text-align: right;"></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {% for room in rooms %}
                                        <tr>
                                            <td>{{ room.id }}</td>
                                            <td>{{ room.title }}</td>
                                            <td>
                                                <button style="float: right;" class="btn" iddd="{{ room.id }}"
                                                        onclick="deletek(this);">删除
                                                </button>

                                            </td>
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div style="width: 100%">
            <div class="">
                <div class="">
                    <form class="form-horizontal form-material">
                        <h4>添加房间</h4>
                        <div class="form-group" style="margin-top: 10px">
                            <label class="col-md-12" style="font-size: 20px">房间名</label>
                            <div class="col-md-12">
                                <input id="k_name" type="text" placeholder="不超过16个字" class="form-control form-control-line">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-12">
                                <button id="publishk" class="btn btn-primary" style="float: right;">添加</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

</div>
</div>
<script src="/static/assets/plugins/jquery/jquery.min.js"></script>
<script src="/static/assets/plugins/bootstrap/js/tether.min.js"></script>
<script src="/static/assets/plugins/bootstrap/js/bootstrap.min.js"></script>


<script>
    function deletek(ths) {
        var kid = $(ths).attr("iddd");
        $.ajax({
            url: window.location.href,
            type: "POST",
            data: {'type': 'delete', 'r_id': kid},
            beforeSend: function (xhr, settings) {
                xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");    // csrf
            },
            success: function (data) {
                if (!data.status) alert(data.msg);
                else window.location.href = "/room-manage";
            }
        });
    }

    $('#publishk').click(function () {
        var k_name = $('#k_name').val();
        $.ajax({
            url: window.location.href,
            type: "POST",
            data: {'type': 'create', 'r_name': k_name},
            beforeSend: function (xhr, settings) {
                xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");    // csrf
            },
            success: function (data) {
                if (!data.status) alert(data.msg);
                else window.location.href = "/room-manage";
            }
        });
    });
</script>
</body>

</html>
